package bh

import android.os.Bundle
import android.webkit.WebSettings
import androidx.appcompat.app.AppCompatActivity
import yyee.llee.mmee.common.databinding.ActivityWeatherWebViewBinding

class DB : AppCompatActivity() {


    private var dataBind: ActivityWeatherWebViewBinding? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        dataBind = ActivityWeatherWebViewBinding.inflate(layoutInflater)


        setContentView(dataBind!!.root)
        initView()
        initListener()
        initData()
    }


    fun initView() {

        val webSettings: WebSettings = dataBind!!.webView.settings

        // 设置允许JS弹窗
        webSettings.javaScriptCanOpenWindowsAutomatically = true
        //支持javascript
        webSettings.javaScriptEnabled = true
        webSettings.domStorageEnabled = true
        // 设置可以支持缩放
        webSettings.setSupportZoom(false)
        // 设置出现缩放工具
        webSettings.builtInZoomControls = false
        //扩大比例的缩放
        webSettings.useWideViewPort = false
        //自适应屏幕
        webSettings.layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN
        webSettings.loadWithOverviewMode = true
    }

    fun initListener() {
        dataBind!!.layoutTitle.ivBack.setOnClickListener {
            finish()
        }
    }

    fun initData() {
        val url = intent.getStringExtra("url")
        val mTitle = intent.getStringExtra("title")
        dataBind!!.layoutTitle.tvTitle.text = mTitle
        url?.let { dataBind!!.webView.loadUrl(it) }
    }

}